﻿package com.lz.football.module.framework
{
    import flash.events.TimerEvent;
    import flash.utils.Timer;
	/**
	 * RBCommand
	 * @author lake
	 * 
	 */
    public class RBCommand implements ICommand 
	{
        private var _timer:Timer;
		/**
		 *延迟执行 S 
		 */		
		private var delayTime :Number;
		public var callBack :Function;
		
        public function RBCommand(t:Number = 0)
		{
			delayTime = t;
        }
		
        public function execute():void
		{
        }
		
        final public function start():void
		{
			_timer = new Timer(int(1000 * delayTime), 1);
			_timer.addEventListener(TimerEvent.TIMER_COMPLETE,onTimerComplete);
            _timer.start();
        }
		
        final public function complete():void
		{
			if(callBack != null) callBack.call();
            destroy();
        }
		
        final public function onTimerComplete(e:TimerEvent):void
		{
            execute();
        }
		
        private function destroy():void
		{
			if(_timer)
			{
				_timer.removeEventListener(TimerEvent.TIMER_COMPLETE,onTimerComplete);
				_timer.stop();
				_timer = null;
			}
        }
    }
}
